<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 头部操作栏 -->
      <div class="layui-form lay-header">
        <div class="toolbar">
          <div class="layui-form-item lay-query-content">
            <div class="lay-query-box">
              <div class="query-lt">
                <div class="layui-inline">
                  <label class="layui-form-label">报工单编号：</label>
                  <div class="layui-input-inline">
                    <input name="code" class="layui-input" type="text" placeholder="请输入报工单编号" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">开工单编号：</label>
                  <div class="layui-input-inline">
                    <input name="workOrderCode" class="layui-input" type="text" placeholder="请输入开工单编号" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">工序名称：</label>
                  <div class="layui-input-inline">
                    <input
                            name="processName2"
                            class="layui-input"
                            type="text"
                            placeholder="请输入工序名称"
                    />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">工序属性：</label>
                  <div class="layui-input-inline">
                    <select name="type">
                      <option value="">请选择工序属性</option>
                      <option value="0">首工序</option>
                      <option value="1">过程工序</option>
                      <option value="2">末工序</option>
                    </select>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">责任工位：</label>
                  <div class="layui-input-inline">
                    <input
                            name="workshopName"
                            class="layui-input"
                            type="text"
                            placeholder="请输入责任工位"
                    />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">质检属性：</label>
                  <div class="layui-input-inline">
                    <select name="qualityAttributes">
                      <option value="">请选择质检属性</option>
                      <option value="0">不质检</option>
                      <option value="1">一物一检</option>
                      <option value="2">简单检测</option>
                    </select>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">物料名称：</label>
                  <div class="layui-input-inline">
                    <input name="skuName" class="layui-input" type="text" placeholder="请输入物料名称" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">物料编码：</label>
                  <div class="layui-input-inline">
                    <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编码" />
                  </div>
                </div>
                <!--状态:tosubmit(0,待提交);confirm(1,已提交);checked(2,已审核)-->
                <div class="layui-inline">
                  <label class="layui-form-label">报工单状态：</label>
                  <div class="layui-input-inline">
                    <select name="status">
                      <option value="">请选择工单状态</option>
                      <option value="tosubmit">待提交</option>
                      <option value="confirm">已提交</option>
                      <option value="checked">已审核</option>
                    </select>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">创建人：</label>
                  <div class="layui-input-inline">
                    <input
                            name="creatorName"
                            class="layui-input"
                            type="text"
                            placeholder="请输入创建人"
                    />
                  </div>
                </div>
              </div>
              <div class="query-rt">
                <div class="layui-inline">
                  <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                  <button class="layui-btn icon-btn color-white" type="reset" lay-filter="resets" lay-submit>重置</button>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="lay-btn-rows">
          <div class="lay-btn-box">
            <div class="lay-btn-lt">
              <button type="button" id="productionTheWorkOrderBtnAdd" class="layui-btn icon-btn color-reseda">添加报工单</button>
              <button type="button" id="confirmSelect" class="layui-btn icon-btn color-reseda" style="display: none">确认选择</button>
            </div>
            <div class="lay-btn-rt"></div>
          </div>
        </div>
      </div>
      <!-- 表格 -->
      <table class="layui-table" id="productionTheWorkOrderTable" lay-filter="productionTheWorkOrderTable"></table>
    </div>
  </div>
</div>

<style>
  .msg-none .layui-none {
    display: none !important;
  }

  .productionTheWorkOrderAddForm .layui-form-item .layui-input-block {
    width: 290px;
  }

  .productionTheWorkOrderAddForm .layui-table-cell {
    height: auto;
  }
</style>

<!-- 表格操作列 -->
<script type="text/html" id="productionTheWorkOrderTableBar">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
  <!-- {{# if(d.status == "tosubmit"){ }} -->
  <a class="layui-btn layui-btn-xs" lay-event="submit">确认提交</a>
  <!-- {{# }else if(d.status =="confirm"){ }} -->
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="check">确认提交</a>
  <!-- {{# }else if(d.status =="checked"&&d.qualityType == 1  ){ }} -->
  <a class="layui-btn  layui-btn-xs" lay-event="setTask">生成质检任务</a>
  <!-- {{# } }} -->
  <button class="layui-btn  layui-btn-xs" lay-event="print">打印</button>

</script>


<!--打印-->
<script type="text/html" id="printPurchaseSignForTemplate">
  <form lay-filter="printPurchaseSignForTemplateForm" class="layui-form open-form printTemplateForm">
    <div class="open-model">
      <div class="open-auto">
        <div class="my-print-box" id="printHtml">

        </div>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" type="button" id="printPurchaseSignFor">打印</button>
      </div>
    </div>
  </form>
</script>
<script src="/admin/assets/libs/jquery/jquery-3.2.1.min.js"></script>
<script src="/admin/assets/libs/jquery/jQuery.print.js.js"></script>

<!--添加报工单-->
<script id="productionTheWorkOrderTemplate" type="text/html">
  <form lay-filter="productionTheWorkOrderAddForm" id="productionTheWorkOrderAddForm" class="layui-form open-form productionTheWorkOrderAddForm">
    <div class="open-model">
      <div class="open-auto">
        <input id="reportWorkId" name="reportWorkId" type="hidden" />
        <input name="processId" type="hidden" />
        <div class="layui-form-item">
          <div class="layui-form-item" style="margin-bottom: 10px;">
            <div class="open-details-title">开工单信息</div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;">开工单：</label>
              <div class="layui-input-block" id="workOrderIdBox" style="margin-left: 165px;">
                <!-- <select
                  id="workOrderId"
                  name="workOrderId"
                  lay-filter="workOrderId"
                  lay-search
                ></select> -->
                <input name="workOrderCode" class="layui-input" type="text" />
                <input name="workOrderId" id="workOrderId" class="layui-input" type="hidden" />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;">所批次号：</label>
              <div class="layui-input-block" style="margin-left: 165px;">
                <input name="batchNumber" class="layui-input" type="text" />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;">所属生产计划：</label>
              <div class="layui-input-block" style="margin-left: 165px;">
                <input disabled name="productionPlanCode" class="layui-input" type="text" readonly="readonly" />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;">排产工序：</label>
              <div class="layui-input-block" style="margin-left: 165px;">
                <input disabled name="processName" class="layui-input" type="text" readonly="readonly" />
              </div>
            </div>
          </div>
          <!-- <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;"
                >物料类型：</label
              >
              <div class="layui-input-block" style="margin-left: 165px;">
                <input
                  name="productTypeName"
                  class="layui-input"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div> -->
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;">物料编号：</label>
              <div class="layui-input-block" style="margin-left: 165px;">
                <input name="skuCode" class="layui-input" disabled type="text" readonly="readonly" />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;">物料名称：</label>
              <div class="layui-input-block" style="margin-left: 165px;">
                <input name="skuName" class="layui-input" disabled type="text" readonly="readonly" />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;">内部规格码：</label>
              <div class="layui-input-block" style="margin-left: 165px;">
                <input disabled name="skuSpec" class="layui-input" type="text" readonly="readonly" />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;">计划生产数：</label>
              <div class="layui-input-block" style="margin-left: 165px;">
                <input name="productionQuantity" class="layui-input" disabled type="text" readonly="readonly" />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;">排产数量：</label>
              <div class="layui-input-block" style="margin-left: 165px;">
                <input name="outputQuantity" class="layui-input" disabled type="text" readonly="readonly" />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;">已完工数量：</label>
              <div class="layui-input-block" style="margin-left: 165px;">
                <input name="reportedOuantity" class="layui-input" disabled type="text" readonly="readonly" />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;">备注：</label>
              <div class="layui-input-block" style="margin-left: 165px;">
                <input name="workRemark" class="layui-input" disabled type="text" readonly="readonly" />
              </div>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-form-item" style="margin-bottom: 10px;">
            <div class="open-details-title">工序报工信息</div>
          </div>
          <table class="layui-table" id="theProcessTable" lay-filter="theProcessTable"></table>
        </div>
        <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;">工位性质：</label>
            <div class="layui-input-block" style="margin-left: 165px;">
              <input name="workstationNature" type="hidden" />
              <input name="workstationNatureName" class="layui-input" type="text" disabled readonly="readonly" />
            </div>
          </div>
        </div>
        <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;">设备/工种：</label>
            <div class="layui-input-block" style="margin-left: 165px;">
              <select id="gzsbId" name="gzsbId" lay-filter="gzsbId" lay-search></select>
            </div>
          </div>
        </div>
        <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;">工位：</label>
            <div class="layui-input-block" style="margin-left: 165px;">
              <input type="hidden" id="workshopName" name="workshopName" />
              <select id="workshopId" name="workshopId" lay-filter="workshopId" lay-search></select>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 135px;">报工图片：</label>
          <div class="layui-upload-drag cardU" id="pictureDiv">
            <!--<i class="layui-icon"></i>
                        <p>点击上传，或将文件拖拽到此处</p>-->
            <input type="hidden" name="reportWorkPic" lay-verify="" data-name="报工图片" />
          </div>
        </div>
        <!-- <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;"
              >仓库类型：</label
            >
            <div class="layui-input-block" style="margin-left: 165px;">
              <select
                id="warehouseTypeId"
                name="warehouseTypeId"
                lay-filter="warehouseTypeId"
                lay-search
              ></select>
            </div>
          </div>
        </div> -->
        <!-- <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;"
              >入库仓库：</label
            >
            <div class="layui-input-block" style="margin-left: 165px;">
              <select id="warehouseId" name="warehouseId" lay-search></select>
            </div>
          </div>
        </div> -->
        <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;">自检状态：</label>
            <div class="layui-input-block" style="margin-left: 165px;">
              <select id="reportWorkCheckStatus" name="reportWorkCheckStatus" lay-search></select>
            </div>
          </div>
        </div>
        <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;">报工数量：</label>
            <div class="layui-input-block" style="margin-left: 165px;">
              <input name="workQuantity" class="layui-input" type="text" lay-verify="number" />
            </div>
          </div>
        </div>
              <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;">不合格数量：</label>
            <div class="layui-input-block" style="margin-left: 165px;">
              <input name="qualifiedNoQuantity" class="layui-input" type="text" lay-verify="number" />
            </div>
          </div>
        </div>
        <div class="layui-col-xs4" id="checkStatusDiv">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;">审核状态：</label>
            <div class="layui-input-block" style="margin-left: 165px;">
              <input name="checkStatusDesc" class="layui-input" type="text" readonly="readonly" />
            </div>
          </div>
        </div>
        <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;">备注：</label>
            <div class="layui-input-block" style="margin-left: 165px;">
              <input id="reportWorkRemark" name="reportWorkRemark" class="layui-input" type="text" />
            </div>
          </div>
        </div>
      </div>
      <div>
        <div class="layui-form-item text-right pd-20" id="productionTheWorkOrderDiv">
          <button class="layui-btn isSubmit" data-type="0" lay-filter="productionTheWorkOrderAddFormSubmit" lay-submit style="display: none;">保存</button>
          <button class="layui-btn layui-btn-primary closeBtn" type="button" ew-event="closeDialog">取消</button>
          <button class="layui-btn" data-type="1" type="button" lay-filter="productionTheWorkOrderAddFormSubmit" lay-submit>提交</button>
        </div>
        <div class="layui-form-item text-right pd-20" id="productionTheWorkOrderAuditDiv">
          <!-- <button class="layui-btn layui-btn-danger" type="button" lay-filter="auditFail" lay-submit>审核不相符</button> -->
          <button class="layui-btn" type="button" lay-filter="auditSuccess" lay-submit>确认提交</button>
        </div>
      </div>
    </div>
  </form>
</script>

<!-- js部分 -->
<script>
  layui.use(["layer", "form", "table", "admin", "laydate", "upload"], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var upload = layui.upload;
    var laydate = layui.laydate;
    let nowData = {};
    let where = [];
    if (typeof parentData !== "undefined") {
      nowData = { ...parentData };
      if (nowData.where) {
        where = nowData.where;
      }
    }
    console.log(nowData);
    if (nowData.eventName === "radio") {
      $("#confirmSelect").show();
      $("#productionTheWorkOrderBtnAdd").hide();
    }
    $("#confirmSelect").click(function () {
      let list = table.checkStatus("productionTheWorkOrderTable").data;
      childData.list = list;
      layer.close(nowData.zindex);
    });

    // 渲染表格
    var insTb = table.render({
      elem: "#productionTheWorkOrderTable",
      url: config.base + "production/productionPlan/admin/productionTheWorkOrder/list",
      page: true,
      cellMinWidth: 100,
      where: { ...where }, //如果无需传递额外参数，可不加该参数
      cols: [
        [
          {
            type: "radio",
            title: "选择",
            hide: nowData.eventName === "radio" ? false : true
          },
          { type: "numbers", title: "序号", align: "center" },
          { field: "code", title: "报工单编码", align: "center", width: 150 },
          {
            field: "workOrderCode",
            title: "所属开工单",
            align: "center",
            width: 150
          },
          { field: "processName", title: "所属工序", align: "center" },
          {
            field: "type",
            title: "工序属性",
            align: "center",
            templet: function (d) {
              if (d.type == 0) {
                return "首工序";
              } else if (d.type == 1) {
                return "过程工序";
              } else if (d.type == 2) {
                return "末工序";
              }
            }
          },
          { field: "workshopName", title: "责任工位", align: "center" },
          {
            field: "qualityType",
            title: "是否质检",
            align: "center",
            templet: (d) => {
              return d.qualityType == 0 ? "不质检" : "质检";
            }
          },
          {
            field: "qualityAttributes",
            title: "质检属性",
            templet: (d) => {
              return d.qualityAttributes && d.qualityType == 1 ? (d.qualityAttributes == 1 ? "一物一检" : "简易检测") : "-";
            }
          },
          {
            field: "skuName",
            title: "物料名称",
            align: "center",
            width: 150
          },
          { field: "skuCode", title: "物料编码", align: "center" },
          // { field: "warehouseName", title: "入库仓库", align: "center" },
          // , {field: 'productTypeName', title: '所属系列', align: 'center'}
          { field: "workQuantity", title: "报工数量", align: "center" },
          {
            field: "qualifiedNoQuantity",
            title: "不合格数",
            align: "center"
          },
          // { field: "workQuantityTotal", align: "center", title: "报工数" },
          // { field: "sendQuantityTotal", align: "center", title: "送检数" },
          // { field: "acceptanceQuantity", align: "center", title: "合格数" },
          // { field: "scrapQuantity", align: "center", title: "报废数" },
          { field: "ypOkRate", align: "center", title: "样品合格率(%)" },
          { field: "bgOkRate", align: "center", title: "报工合格率(%)" },
          // , {field: 'finishDate', title: '预计完工时间', align: 'center'}
          { field: "creatorName", title: "创建人", align: "center" },
          { field: "createTime", title: "创建时间", align: "center" },
          {
            field: "reportWorkCheckStatusName",
            title: "自检状态",
            align: "center"
          },
          { field: "checkStatusDesc", title: "审核状态", align: "center" },
          { field: "statusDesc", title: "状态", align: "center" },
          {
            align: "center",
            toolbar: "#productionTheWorkOrderTableBar",
            title: "操作",
            fixed: "right",
            hide: nowData.eventName === "radio",
            width: 300
          }
        ]
      ]
    });

    // 工具条点击事件
    table.on("tool(productionTheWorkOrderTable)", async function (obj) {
      var data = obj.data;
      if (obj.event === "submit") {
        //确认提交
        productionTheWorkOrderModel("submit", data);
      } else if (obj.event === "check") {
        const res = await admin.reqPro("production/productionPlan/admin/productionTheWorkOrder/detail/" + data.id);
        //确认提交
        productionTheWorkOrderModel("check", res.data);
      } else if (obj.event === "detail") {
        //详情
        const res = await admin.reqPro("production/productionPlan/admin/productionTheWorkOrder/detail/" + data.id);

        productionTheWorkOrderModel("detail", res.data);
      } else if (obj.event === 'print') {
        showPrintPurchaseSignForTemplate(data)
      } else if (obj.event === "setTask") {
        admin.putTempData("workOrderQuaTaskInfoData",null);

        admin.formOpen({
          type: 1,
          area: ["80%", "85%"],
          style: "font-size: 20px;",
          title: "生成质检任务",
          path: "components/res/quality/workOrderQualityTaskForm.html",
          success: function () {
            parentData.eventName = "setTask";
            parentData.data = data;
          }
        });
      }
    });
    form.render("select");
    //监听排序
    table.on("sort(productionTheWorkOrderTable)", function (obj) {
      table.reload("productionTheWorkOrderTable", {
        initSort: obj,
        where: {
          sort: obj.field,
          order: obj.type
        }
      });
    });

    // 搜索
    form.on("submit(formSubSearchLog)", function (data) {
      console.log(123, data.field);

      insTb.reload({ where: { ...data.field, ...where }, page: { curr: 1 } }, "data");
      return false;
    });

    // 重置搜索
    form.on("submit(resets)", (data) => {
      insTb.reload({ where: admin.resetSearch(data.field), page: { curr: 1 } }, "data");
    });

    // 添加按钮点击事件
    $("#productionTheWorkOrderBtnAdd").click(function () {
      productionTheWorkOrderModel("submit", null);
    });

    // 添加报工单
    function productionTheWorkOrderModel(type, data) {
      let titleName;
      if (type === "submit") {
        titleName = "添加报工单信息";
      } else if (type === "check") {
        titleName = "报工单审核";
      } else if (type === "detail") {
        titleName = "报工单详情";
      }
      admin.open({
        type: 1,
        area: ["82%", "90%"],
        title: titleName,
        content: $("#productionTheWorkOrderTemplate").html(),
        success: async function () {
          $("#workOrderIdBox").click(function () {
            admin.formOpen({
              area: "90%",
              offset: "50px",
              title: "开工单列表",
              path: "components/productionPlan/productionWorkOrder.html",
              success: function () {
                parentData.eventName = "radio";
                parentData.where = {
                  statusFlag: 1,
                  status: "inproduction"
                };
              },
              end: async function () {
                if (childData.list && childData.list.length > 0) {
                  const res1 = await admin.reqPro("production/productionPlan/admin/productionWorkOrder/detail/" + childData.list[0].id);
                  let obj = res1.data;
                  if (obj.workstationNatureName == 1) {
                    layer.msg("开工单已结束，不能继续领料", { icon: 2 });
                    return;
                  }

                  form.val("productionTheWorkOrderAddForm", {});
                  form.val("productionTheWorkOrderAddForm", {
                    ...obj,
                    workOrderCode: obj.code,
                    workOrderId: obj.id
                  });
                  const res2 = await admin.reqPro("enterprise/res/admin/setting/workStation/list", {
                    professionId: res1.data.workstationNature == 1 ? res1.data.gzsbId : "",
                    deviceModelSpuId: res1.data.workstationNature == 2 ? res1.data.gzsbId : ""
                  });
                  admin.initDataSelect(res1.data.deviceTypeList, null, "gzsbId", null, "设备机型", "deviceName", "id");
                  form.on("select(gzsbId)", async function (d) {
                    $("#workshopId").empty();
                    $("#workshopId").val("");
                    form.render("select");
                    let workstationNature = $("#workstationNature").val();

                    if (d.value) {
                      const res1 = await admin.reqPro("enterprise/res/admin/setting/workStation/list", {
                        // gzsbId: d.value,
                        professionId: workstationNature == 1 ? d.value : "",
                        deviceModelSpuId: workstationNature == 2 ? d.value : ""
                      });
                      admin.initDataSelect(res1.data, null, "workshopId", null, "工位", "name", null);
                      form.on("select(workshopId)", async function (d) {
                        $("#workshopName").val();
                        $("#workshopName").val(d.elem[d.elem.selectedIndex].text);
                      });
                    }
                  });
                  // admin.initDataSelectPro(
                  //   "enterprise/res/admin/setting/workStation/list",
                  //   {
                  //     deviceModelSpuIds:
                  //       obj.workstationNatureName == "设备工位"
                  //         ? obj.deviceTypeList.map((v) => v.id).join(",")
                  //         : "",
                  //     professionIds:
                  //       obj.workstationNatureName == "人工工位"
                  //         ? obj.deviceTypeList.map((v) => v.id).join(",")
                  //         : "",
                  //   },
                  //   "workshopId",
                  //   "工位",
                  //   (d, obj) => {
                  //     $("#workshopName").val(obj.name);
                  //   }
                  // );
                  console.log(123, obj);
                }
              }
            });
          });
          // 开工单列表
          // admin.initDataSelect(
          //   "production/productionPlan/admin/productionWorkOrder/list",
          //   {
          //     status: "inproduction",
          //     limit: 9999,
          //   },
          //   "workOrderId",
          //   data ? data.workOrderId : null,
          //   "开工单",
          //   "code",
          //   null
          // );

          // 开工单信息-数据回显
          if (data) {
            if (type == "detail") {
              admin.setFormDisable("#productionTheWorkOrderAddForm", true);
            }

            const res = await admin.reqPro(
              "production/productionPlan/admin/productionWorkOrder/getWorkOrderDetails",
              {
                workOrderId: data.workOrderId
              },
              "GET"
            );
            if (res.code == 200) {
              let obj = res.data;
              await admin.initDataSelectPro(
                "enterprise/res/admin/setting/workStation/list",
                {
                  deviceModelSpuIds: obj.workstationNatureName == "设备工位" ? obj.deviceTypeList.map((v) => v.id).join(",") : "",
                  professionIds: obj.workstationNatureName == "人工工位" ? obj.deviceTypeList.map((v) => v.id).join(",") : ""
                },
                "workshopId",
                "工位",
                (d, obj) => {
                  $("#workshopName").val(obj.name);
                }
              );
              form.render();

              form.val("productionTheWorkOrderAddForm", obj);
            } else {
              layer.msg(res.msg, { icon: 2 });
            }
          }

          //开工单选择事件
          // form.on("select(workOrderId)", function (selectData) {
          //   admin.req(
          //     "production/productionPlan/admin/productionWorkOrder/detail/" +
          //       selectData.value,
          //     // "production/productionPlan/admin/productionWorkOrder/getWorkOrderDetails",
          //     {
          //       // workOrderId: selectData.value,
          //     },
          //     function (res) {
          //       if (res.code == 200) {
          //         $("#gzsbId").empty(); //清空
          //         form.val("productionTheWorkOrderAddForm", {});
          //         form.val("productionTheWorkOrderAddForm", res.data);
          //         admin.initDataSelect(
          //           res.data.deviceTypeList,
          //           null,
          //           "gzsbId",
          //           null,
          //           "设备机型",
          //           "deviceName",
          //           "id"
          //         );
          //         form.on("select(gzsbId)", async function (d) {
          //           $("#workshopId").empty();
          //           $("#workshopId").val("");
          //           let workstationNature = $("#workstationNature").val();
          //           if (d.value) {
          //             const res1 = await admin.reqPro(
          //               "enterprise/res/admin/setting/workStation/list",
          //               {
          //                 // gzsbId: d.value,
          //                 professionId: workstationNature == 1 ? d.value : "",
          //                 deviceModelSpuId:
          //                   workstationNature == 2 ? d.value : "",
          //               }
          //             );
          //             admin.initDataSelect(
          //               res1.data,
          //               null,
          //               "workshopId",
          //               null,
          //               "工位",
          //               "name",
          //               null
          //             );
          //             form.on("select(workshopId)", async function (d) {
          //               $("#workshopName").val();
          //               $("#workshopName").val(
          //                 d.elem[d.elem.selectedIndex].text
          //               );
          //               // let workstationNature = $("#workstationNature").val();
          //             });
          //           }
          //         });

          //         form.render();
          //       } else {
          //         layer.msg(res.msg, { icon: 2 });
          //       }
          //     },
          //     "GET"
          //   );
          // });

          // 报工图片-回显
          if (data) {
            var picture = data.reportWorkPic;
            if (picture) {
              $("#pictureDiv").html('<img src="' + picture + '" alt="上传成功后渲染" style="max-width: 196px"><input type="hidden" name="reportWorkPic" value="' + picture + '">');
            }
          }

          //仓库类型
          admin.initDataSelect("enterprisecab/warehouse/admin/warehouseType/list", { limit: 9999 }, "warehouseTypeId", data ? data.warehouseTypeId : null, "仓库类型", null, null);

          // 仓库-数据回显
          if (data) {
            admin.initDataSelect(
              "enterprisecab/warehouse/admin/warehouse/list",
              {
                limit: 9999,
                warehouseTypeId: data.warehouseTypeId
              },
              "warehouseId",
              data ? data.warehouseId : null,
              "仓库",
              null,
              null
            );
          }

          //仓库类型选择事件
          form.on("select(warehouseTypeId)", function (selectData) {
            $("#warehouseId").empty();
            admin.initDataSelect(
              "enterprisecab/warehouse/admin/warehouse/list",
              {
                limit: 9999,
                warehouseTypeId: selectData.value
              },
              "warehouseId",
              null,
              "仓库",
              null,
              null
            );
          });
          //自检状态
          admin.getDictList("reportWorkCheckStatus", "report_work_check_status", data ? data.reportWorkCheckStatus : null, "自检状态");

          //图片上传
          upload.render({
            elem: "#pictureDiv",
            url: config.upload_url + "uploadFile?path=" + img_path,
            auto: true,
            acceptMime: "image/*",
            headers: { authorization: "Bearer " + config.getToken() },
            done: function (res) {
              layer.closeAll("loading");
              layer.msg("上传成功");
              var imgUrl = res.data.url;
              $("#pictureDiv").html('<img src="' + imgUrl + '" alt="上传成功后渲染" style="max-width: 196px"><input type="hidden" name="reportWorkPic" value="' + imgUrl + '">');
            },
            error: function (data) {
              layer.closeAll("loading");
            }
          });

          //提交按钮隐藏
          if (type === "submit") {
            $("#productionTheWorkOrderDiv").show();
            $("#productionTheWorkOrderAuditDiv").hide();
            $("#checkStatusDiv").hide();
          } else if (type === "detail") {
            $("#productionTheWorkOrderDiv").hide();
            $("#productionTheWorkOrderAuditDiv").hide();
            $("#checkStatusDiv").show();
          } else if (type === "check") {
            $("#productionTheWorkOrderDiv").hide();
            $("#productionTheWorkOrderAuditDiv").show();
            $("#checkStatusDiv").hide();
          }

          //数据回显
          if (data) {
            $("#reportWorkId").val(data.id);
            $("#reportWorkRemark").val(data.remark);
            form.val("productionTheWorkOrderAddForm", data);
          }

          // 提交数据
          form.on("submit(productionTheWorkOrderAddFormSubmit)", function (d) {
            console.info(d.field, 9090);
            // return
            admin.req(
              "production/productionPlan/admin/productionTheWorkOrder/add",
              JSON.stringify(d.field),
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("productionTheWorkOrderTable");
                  layer.closeAll();
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "POST",
              true,
              "application/json; charset=utf-8"
            );
            return false;
          });

          //审核相符
          form.on("submit(auditSuccess)", function (d) {
            layer.load(2);
            admin.req(
              `production/productionPlan/admin/productionTheWorkOrder/audit/${d.field.reportWorkId}/correspond`,
              {},
              function (res) {
                layer.closeAll("loading");
                layer.msg(res.msg, { icon: 1 });
                layer.closeAll();
                table.reload("productionTheWorkOrderTable");
              },
              "PUT"
            );

            return;

            d.field.id = d.field.reportWorkId;
            d.field.status = "checked";
            d.field.checkStatus = "correspond";
            layer.load(2);
            admin.req(
              "production/productionPlan/admin/productionTheWorkOrder/update",
              JSON.stringify(d.field),
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("productionTheWorkOrderTable");
                  layer.closeAll();
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "PUT",
              true,
              "application/json; charset=utf-8"
            );
            return false;
          });

          //审核不相符
          form.on("submit(auditFail)", function (d) {
            layer.load(2);

            admin.req(
              `production/productionPlan/admin/productionTheWorkOrder/audit/${d.field.reportWorkId}/discrepancy`,
              {},
              function (res) {
                layer.closeAll("loading");
                layer.msg(res.msg, { icon: 1 });
                layer.closeAll();
                table.reload("productionTheWorkOrderTable");
              },
              "PUT"
            );

            return;
            d.field.id = d.field.reportWorkId;
            d.field.status = "checked";
            d.field.checkStatus = "discrepancy";
            admin.req(
              "production/productionPlan/admin/productionTheWorkOrder/update",
              JSON.stringify(d.field),
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("productionTheWorkOrderTable");
                  layer.closeAll();
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "PUT",
              true,
              "application/json; charset=utf-8"
            );
            return false;
          });
        }
      });
    }

        // 打印入库签收单
        function showPrintPurchaseSignForTemplate(data) {
      admin.open({
        type: 1,
        area: ["1060px", "800px"],
        offset: '65px',
        title: '打印',
        content: $('#printPurchaseSignForTemplate').html(),
        success: function () {
          let html = "";
          admin.req("production/productionPlan/admin/productionTheWorkOrder/printTheWork/"+data.id, {}, function (res) {
            if (res.code === 200) {
              let detailList = res.data;
              let itemData = res.data
              let customerObj = {}, auditName = '';
              // admin.reqSync("enterprise/sell/admin/contactInfo/list", {selCustomerId: res.data.customerId}, function (obj) {
              //   if (obj.code == 200) {
              //     customerObj = obj.data.length > 0 ? obj.data[0] : {};
              //   }
              // });
              // // 获取审核人
              // admin.reqSync("user/admin/user/list", {limit: 9999}, function (obj) {
              //   if (obj.code == 200) {
              //     auditName = obj.data.find(v => v.id === res.data.auditId).name || '';
              //   }
              // });
              html += `<div class="print-title">生产报工单</div>
          <div class="flexCt print-tip-info">
            <div class="company">部门：${data.departmentName}</div>
             <div class="company">工位：${data.workshopName}</div>
            <div class="time">${data.createTime}</div>
          </div>
          <div class="print-table">
            <div class="print-view">
              <div class="print-nape ">
                <div class="cell">
                    <div class="name w-120 justify">报工单：</div>
                    <div class="val flex-1">${data.code}</div>
                </div>
                <div class="cell">
                    <div class="name w-120 justify">所属工序：</div>
                    <div class="val flex-1">${itemData.processName}</div>
                </div>
              </div>
              <div class="print-nape ">
                <div class="cell">
                   <div class="name w-120 justify">所属开工单：</div>
                   <div class="val flex-1">${data.workOrderCode}</div>
                </div>
                <div class="cell">
                    <div class="name w-120 justify">所属计划</div>
                    <div class="val flex-1">${itemData.productionPlanId}</div>
                </div>
              </div>
              <div class="print-nape ">
                <div class="cell">
                   <div class="name w-120 justify">报工数：</div>
                   <div class="val flex-1">${itemData.workQuantity}</div>
                </div>
                <div class="cell">
                    <div class="name w-120 justify">工位性质：</div>
                   <div class="val flex-1">${itemData.workstationNatureName || ''}</div>
                </div>
              </div>
             
              
              <div class="print-nape ">
                <div class="cell">
                   <div class="name w-120 justify">设备/工种：</div>
                   <div class="val flex-1">${itemData.gzsbName}</div>
                </div>
                <div class="cell">
                    <div class="name w-120 justify">自检状态：</div>
                    <div class="val flex-1">${itemData.reportWorkCheckStatus}</div>
                </div>
              </div>
              <div class="print-nape">
                <div class="cell  flex-1">
                  <div class="th v-60" style="padding: 0">序号</div>
                  <div  class="name flex-1">物料名称</div>
                  <div  class="name flex-1">物料编号</div>
                   <div class="name flex-1">规格码</div>
                  <div class="th">报工合格数</div>
                  <div class="th" style="padding: 0;">不合格数</div>
                  <div class="th" style="padding: 0;">样品合格率(%)</div>
                  <div class="th" style="padding: 0;">报工合格率(%)</div>
                  
                </div>
              </div>`;
              let list = detailList.length > 10 ? detailList.slice(0, 10) : detailList;
              let fillValue = {}, allMoney = new Decimal(0);
              // let filledArray = [...list, ...Array.from({ length: 10 - list.length }, () => fillValue)]||[];
              let filledArray = [data]
              filledArray.forEach((item, index) => {
                if (item.totalMoney) {
                  allMoney = allMoney.add(new Decimal(item.totalMoney))
                }
                html += `<div class="print-nape">
                    <div class="cell w-100">
                      <div class="td v-60" style="padding: 0">${index + 1}</div>
                      <div  class="name flex-1">${item.skuName || ''}</div>
                      <div  class="name flex-1">${item.skuCode || ''}</div>
                      <div  class="name flex-1">${item.skuSpec || ''}</div>
                      <div class="td">${item.qualifiedQuantity || ''}</div>
                      <div class="td">${item.qualifiedNoQuantity != undefined ? item.qualifiedNoQuantity : ''}</div>
                      <div class="td">${item.ypOkRate != undefined ? item.ypOkRate : ''}</div>
                      <div class="td">${item.bgOkRate != undefined ? item.bgOkRate : ''}</div>
                    </div>
                  </div>`
              });
              html += `<div class="print-nape nape-btm">
                <div class="btm-sign lt">负责人签名与盖公司印章：</div>
                <div class="sign-rt flex-1">
                  <div class="cell w-100">
                    <div class="name flex-1">制单人：</div>
                    <div class="name flex-1">审核人：</div>
                  </div>
                  <div class="cell w-100">
                    <div class="val flex-1">${itemData.createName}</div>
                    <div class="val flex-1">${itemData.modifierName}</div>
                  </div>
                </div>
              </div>
            </div>
          </div>`
              $('#printHtml').html(html);

              $("#printPurchaseSignFor").click(function () {
                $('#printHtml').print({
                  debug: false,
                  importCSS: true,
                  printContainer: true,
                  operaSupport: false
                });
              })
            }
          });
        }
      })
    }
  });
</script>

<style>
  .cardU {
    background-image: url(../../assets/images/card_u.png);
    background-repeat: no-repeat;
    background-position: center;
    width: 200px;
    height: 150px;
    margin-left: 0px;
    padding: 0;
  }

  .cardU img {
    width: 100%;
    height: 100%;
  }
</style>
